#include <QTGui>

#include "mainwindow.h"
#include "dlgcapisaldi.h"
#include "dlgimpostazioniprogetto.h"
#include "earthquake_global.h"

MainWindow::MainWindow(QWidget *parent)
{
   // scene = new QGraphicsScene(QRectF(0, 0, 200, 200));
   // view = new QGraphicsView(scene);

   // scene1 = new QGraphicsScene(QRectF(0, 0, 200, 200));
   // view1 = new QGraphicsView(scene1);

   // mdiarea = new QMdiArea;
   // window1 = new QMdiSubWindow;
   // window2 = new QMdiSubWindow;

   // window1 = mdiarea->addSubWindow(view);
   // window2 = mdiarea->addSubWindow(view1);

   // mdiarea->tileSubWindows();
   // setCentralWidget(mdiarea);
    textedit = new QTextEdit;  
    textedit->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding);
    textedit->resize(1000,300);
    setCentralWidget(textedit);
   // dock_muro = new QDockWidget(tr("Muri in c.a."),this);
   // dock_muro->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);

   // dock_sezione = new QDockWidget(tr("Sezioni in c.a."),this);
   // dock_sezione->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);

   // setDockNestingEnabled(true);
   /*
/////////////////////////////////////////////////////////////////////////
   SlvWallMap wall_map;
   SlvWall *pwall_1 = new SlvWall;
   SlvWall *pwall_2 = new SlvWall;
   SlvWall *pwall_3 = new SlvWall;
   wall_map.insert("muro n.1", pwall_1);
   wall_map.insert("muro n.2", pwall_2);
   wall_map.insert("muro n.3", pwall_3);
/////////////////////////////////////////////////////////////////////////

/////////////////////////////////////////////////////////////////////////

   tree = new treePrjWall(wall_map,this);
   tree->setColumnCount(1);
   QTreeWidgetItem *newitem1 = new QTreeWidgetItem();
   newitem1->setText(0,"muro n.1");
   tree->insertTopLevelItem(0,newitem1);
   QTreeWidgetItem *newitem2 = new QTreeWidgetItem();
   newitem2->setText(0,"muro n.2");
   tree->addTopLevelItem(newitem2);
   QTreeWidgetItem *newitem3 = new QTreeWidgetItem();
   newitem3->setText(0,"muro n.3");
   tree->addTopLevelItem(newitem3);

   dock_muro->setWidget(tree);
   addDockWidget(Qt::LeftDockWidgetArea,dock_muro);

   tree_sez = new treePrjSez(this);
   tree_sez->setColumnCount(1);
   QTreeWidgetItem *sezitem1 = new QTreeWidgetItem();
   sezitem1->setText(0,"sezione n.1");
   tree_sez->insertTopLevelItem(0,sezitem1);
   QTreeWidgetItem *sezitem2 = new QTreeWidgetItem();
   sezitem2->setText(0,"sezione n.2");
   tree_sez->addTopLevelItem(sezitem2);
   QTreeWidgetItem *sezitem3 = new QTreeWidgetItem();
   sezitem3->setText(0,"sezione n.3");
   tree_sez->addTopLevelItem(sezitem2);

   dock_sezione->setWidget(tree_sez);
   addDockWidget(Qt::LeftDockWidgetArea,dock_sezione);

/////////////////////////////////////////////////////////////////////////
*/
   createActions();
   createMenus();

}

void MainWindow::createActions(void)
{
    newAction = new QAction(tr("&Nuovo"), this);
    newAction->setIcon(QIcon(":/images/new.png"));
    newAction->setShortcut(tr("Ctrl+N"));
    newAction->setStatusTip(tr("Crea un nuovo file"));
    connect(newAction, SIGNAL(triggered()), this, SLOT(newFile()));

    draw1Action = new QAction(tr("&Disegno 1"), this);
    // newAction->setIcon(QIcon(":/images/new.png"));
    draw1Action->setShortcut(tr("Ctrl+1"));
    draw1Action->setStatusTip(tr("Disegno n.1"));
    connect(draw1Action, SIGNAL(triggered()), this, SLOT(drawTest_1()));

    draw2Action = new QAction(tr("&Disegno 2"), this);
    // newAction->setIcon(QIcon(":/images/new.png"));
    draw2Action->setShortcut(tr("Ctrl+2"));
    draw2Action->setStatusTip(tr("Disegno n.2"));
    connect(draw2Action, SIGNAL(triggered()), this, SLOT(drawTest_2()));

    view1Action = new QAction(tr("&Vista 1"), this);
    // newAction->setIcon(QIcon(":/images/new.png"));
    // draw1Action->setShortcut(tr("Ctrl+1"));
    view1Action->setStatusTip(tr("Vista n.1"));
    connect(view1Action, SIGNAL(triggered()), this, SLOT(onView1()));

    view2Action = new QAction(tr("&Vista 2"), this);
    // newAction->setIcon(QIcon(":/images/new.png"));
    // draw1Action->setShortcut(tr("Ctrl+1"));
    view2Action->setStatusTip(tr("Vista n.2"));
    connect(view2Action, SIGNAL(triggered()), this, SLOT(onView2()));

    openDlgCapisaldiAction = new QAction(tr("&Capisaldi"), this);
    // newAction->setIcon(QIcon(":/images/new.png"));
    // draw1Action->setShortcut(tr("Ctrl+1"));
    openDlgCapisaldiAction->setStatusTip(tr("Capisaldi"));
    connect(openDlgCapisaldiAction, SIGNAL(triggered()), this, SLOT(onOpenDlgCapisaldi()));

    openDlgImpostazioniProgettoAction = new QAction(tr("&Progetto"), this);
    connect(openDlgImpostazioniProgettoAction, SIGNAL(triggered()), this, SLOT(onOpenDlgImpostazioniProgetto()));

}

void MainWindow::createMenus(void)
{
    fileMenu = menuBar()->addMenu(tr("&File"));
    fileMenu->addAction(newAction);

    fileMenu = menuBar()->addMenu(tr("&Viste"));
    fileMenu->addAction(view1Action);
    fileMenu->addAction(view2Action);

    fileMenu = menuBar()->addMenu(tr("&Disegno"));
    fileMenu->addAction(draw1Action);
    fileMenu->addAction(draw2Action);

    fileMenu = menuBar()->addMenu(tr("&Sismica"));
    fileMenu->addAction(openDlgCapisaldiAction);

    fileMenu = menuBar()->addMenu(tr("&Impostazioni"));
    fileMenu->addAction(openDlgImpostazioniProgettoAction);


// CREA UN MENU POPUP
    /*
    treeViewPopUpMenu = new QMenu("prova");
    treeViewPopUpMenu->addAction(newMuroAction);
    treeViewPopUpMenu->addAction(deleteMuroAction);
    treeViewPopUpMenu->addAction(renameMuroAction);
    */
}

void MainWindow::newFile(void)
{
    QMessageBox msgBox;
    msgBox.setText("SLOT ---> nuovo file");
    msgBox.exec();
}

void MainWindow::drawTest_1()
{
    QMessageBox msgBox;
    msgBox.setText("SLOT ---> test 1");
    msgBox.exec();
}

void MainWindow::drawTest_2()
{
    QMessageBox msgBox;
    msgBox.setText("SLOT ---> test 2");
    msgBox.exec();
}

void MainWindow::contextMenuEvent(QContextMenuEvent *event)
{
/*  QMenu menu(this);
    menu.addAction(cutAct);
    menu.addAction(copyAct);
    menu.addAction(pasteAct);
    menu.exec(event->globalPos());

    treeViewPopUpMenu->exec(event->globalPos());
*/

}


void MainWindow::onView2(void)
{
    QMessageBox msgBox;
    msgBox.setText("SLOT ---> vista 2");
    msgBox.exec();
}

void MainWindow::onView1(void)
{
    QMessageBox msgBox;
    msgBox.setText("SLOT ---> vista 1");
    msgBox.exec();
}

void MainWindow::onOpenDlgCapisaldi(void)
{
    DlgCapisaldi* ui=new DlgCapisaldi(this);

    if(ui->exec())
    {
    }
    delete ui;
}

void MainWindow::onOpenDlgImpostazioniProgetto(void)
{
    DlgImpostazioniProgetto* ui=new DlgImpostazioniProgetto(this);

    if(ui->exec())
    {
    }
    delete ui;
}

void MainWindow::new_Muro(void)
{
    QMessageBox msgBox;
    msgBox.setText("NUOVO MURO");
    msgBox.exec();
}

void MainWindow::new_Sezione(void)
{
    QMessageBox msgBox;
    msgBox.setText("NUOVA SEZIONE");
    msgBox.exec();
}


MainWindow::~MainWindow()
{
    // delete ui;
}
